/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：LearningScreen.java <br>
 * 创建时间：2013-9-3 下午12:51:49 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.GameConstants;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.data.Room;
import lostland.gmud.exv2.data.Skill;
import lostland.gmud.exv2.ui.core.ProgressScreen;
import lostland.gmud.exv2.ui.core.YesNoScreen;

/**
 * 类名：LearningScreen <br>
 * 说明：请教界面
 *
 * @author 12548
 */
public class LearningScreen extends ProgressScreen {

	int sklid;
	int limit;


	public LearningScreen(int sklid, int limit) {
		super(GameConstants.TICK_TIME, Gmud.mc.getAttr(Room.ATTR_WXG) / 2, (Gmud.mc.skills[sklid] + 1) * (Gmud.mc.skills[sklid] + 1), Gmud.mc.learning[sklid], Gmud.mc.skills[sklid]);
		this.sklid = sklid;
		this.limit = limit;
	}

	private void onContinue() {
		if (!Gmud.mc.expcanlearn(Gmud.mc.skills[sklid] + 1)) {
			new NotificationScreen("你的武学经验不足，无法领会更深的功夫").replaceCurrent();
		} else if (Gmud.mc.skills[sklid] > limit) {
			new NotificationScreen("你的功夫已经不输为师了，真是可喜可贺呀！").replaceCurrent();
		} else {
			new LearningScreen(sklid, limit).replaceCurrent();
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ProgressScreen#onComplete()
	 */
	@Override
	public void onComplete() {
		Gmud.mc.skills[sklid]++;
		Gmud.mc.learning[sklid] = 0;
		if (Game.uninterruptible) {
			onContinue();
		} else {
			new YesNoScreen("继续学习吗？") {

				@Override
				protected void onYes() {
					getGame().popScreen();
					onContinue();
				}

				@Override
				protected void onNo() {
					getGame().popScreen();
					getGame().popScreen();
				}

			}.pushToGame();
		}
	}


	@Override
	public void tick(int multiplier) {
		if (sklid == Skill.KIND_ZHISHI) {
			int cost;
			if (Gmud.mc.skills[sklid] < 20) {
				cost = 5;
			} else if (Gmud.mc.skills[sklid] < 30) {
				cost = 10;
			} else if (Gmud.mc.skills[sklid] < 50) {
				cost = 50;
			} else if (Gmud.mc.skills[sklid] < 60) {
				cost = 100;
			} else if (Gmud.mc.skills[sklid] < 80) {
				cost = 150;
			} else if (Gmud.mc.skills[sklid] < 100) {
				cost = 300;
			} else if (Gmud.mc.skills[sklid] < 120) {
				cost = 500;
			} else {
				cost = 1000;
			}

			cost *= multiplier;

			if (Gmud.mc.gold < cost) {
				new NotificationScreen("没钱读什么书啊，回去攒够学费再来吧！").replaceCurrent();
				ok = false;
				return;
			} else {
				Gmud.mc.earnMoney(-cost);
			}
		}

		if (Gmud.mc.potential <= 0) {
			Gmud.mc.setPotential(0);
			new NotificationScreen("你的潜能已经发挥到极限了").replaceCurrent();
			ok = false;
			return;
		}

		Gmud.mc.setPotential(Gmud.mc.potential - multiplier);
		if (Gmud.mc.potential <= 0) {
			Gmud.mc.setPotential(0);
		}

		super.tick(multiplier);
	}


	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ProgressScreen#binding(int)
	 */
	@Override
	protected void binding(int now) {
		Gmud.mc.learning[sklid] = now;
	}

}
